<template>
  <view class="contain flex f-c f-j-s">
    <view v-if="!isXcx" class="padding-15">
      <!-- #ifndef H5 -->
      <view :style="{'padding-top': top+30+'px'}"></view>
      <!-- #endif -->
      <view class="padding-20"></view>
      <view class="padding-6"></view>
      <view class="padding-lr12">

        <u-tabs :list="tabsList"
                :current="tabsCurrent"
                :is-scroll="false"
                @click="tabsClick"
                @change="tabsChange"></u-tabs>

        <view v-show="tabsCurrent === 0">
          <view class="margin-t10">
            <view class="f20-size f-w-b">密码登录</view>
            <view class="f12-size f-w margin-t10">欢迎使用联动素材下载，祝您选载愉快</view>
          </view>
          <view class="padding-tb6"></view>
          <view class="flex h-50 b-radius-30 bg-color-f1 margin-t8">
            <view class="flex  f-a-c f-j-c f-s-0 icon-item f-w-b">+86</view>
            <view class="flex flex-1 padding-lr12">
              <u-input class="f16-size margin-t10" v-model="formPhonePasswordLogin.phone" type="number" maxlength="11"
                       :placeholder="i18n['请输入手机号码']" clearable></u-input>
            </view>
          </view>
          <view class="flex h-50 b-radius-30 bg-color-f1 margin-t8">
            <view class="flex  f-a-c f-j-c f-s-0 icon-item f-w-b">
              <image class="w-20" src="../../static/images/login_passport.png" mode="widthFix"></image>
            </view>
            <view class="flex flex-1 padding-lr12">
              <u-input class="f16-size margin-t10" v-model="formPhonePasswordLogin.password" type="password"
                       :placeholder="i18n['请输入登录密码']" clearable></u-input>
            </view>
          </view>
        </view>
        <view v-show="tabsCurrent === 1">
          <view class="margin-t10">
            <view class="f20-size f-w-b">验证码登录</view>
            <view class="f12-size f-w margin-t10">{{ i18nXieyi['未注册手机号将自动为您创建账号'] }}</view>
          </view>
          <view class="padding-tb6"></view>
          <view class="flex h-50 b-radius-30 bg-color-f1 margin-t8">
            <view class="flex  f-a-c f-j-c f-s-0 icon-item f-w-b">+86</view>
            <view class="flex flex-1 padding-lr12">
              <u-input class="f16-size margin-t10" v-model="formPhoneCodeLogin.phone" type="number" maxlength="11"
                       :placeholder="i18n['请输入手机号码']" clearable></u-input>
            </view>
          </view>
          <view class="flex h-50 b-radius-30 bg-color-f1 margin-t8">
            <view class="flex  f-a-c f-j-c f-s-0 icon-item f-w-b">
              <image class="w-20" src="../../static/images/login_code.png" mode="widthFix"></image>
            </view>
            <view class="flex flex-1 padding-lr12">
              <u-input class="f16-size margin-t10" v-model="formPhoneCodeLogin.sms" type="tel"
                       :placeholder="i18n['请输入手机验证码']" clearable></u-input>
            </view>
            <view class="padding-6">
              <phone-code :phone="formPhoneCodeLogin.phone" :code="formPhoneCodeLogin.code"
                          :sendType="4" ref="phoneCodeRefGzh"></phone-code>
            </view>
          </view>
        </view>
        <!--        <view class="flex h-50 b-radius-30 bg-color-f1 margin-t8 over-h">-->
        <!--          <view class="flex  f-a-c f-j-c f-s-0 icon-item f-w-b">-->
        <!--            <image class="w-20" src="../../static/images/login_code.png" mode="widthFix"></image>-->
        <!--          </view>-->
        <!--          <view class="flex flex-1 padding-lr12">-->
        <!--            <input v-model="code" type="number" :placeholder="i18n['图形验证码']">-->
        <!--          </view>-->
        <!--          <view class="flex f-a-c f-s-0">-->
        <!--            <img-code ref="imgCode" class="flex  h-30"></img-code>-->
        <!--          </view>-->
        <!--        </view>-->


        <view class="padding-15 safe-area box-c">
          <view class="flex f-a-c f-j-c ">
            <!-- #ifdef MP-WEIXIN -->
            <!--            <button class="flex f-a-c bg-color-f7 h-36 b-radius-30 padding-lr15" @click="getUserInfo">-->
            <!--              <image class="w-20 margin-r4" src="../../static/images/wx_icon.png" mode="widthFix"></image>-->
            <!--              <text>{{ i18n['微信快捷登录'] }}</text>-->
            <!--            </button>-->
            <!-- #endif -->
          </view>
          <view @click="isAgree = !isAgree" class="flex f-a-c margin-t12">
            <view class="padding-6"></view>
            <text :class="isAgree ? 'van-icon-checked t-color-y' : 'van-icon-circle t-color-b'"
                  class="flex f-a-c f-j-c van-icon  f16-size margin-r4"></text>
            <text class="margin-r4 flex f-s-0">{{ i18n['已阅读并同意'] }}</text>
            <text @click="go('/pagesB/user/rules?type=1')" class="t-color-blue1 margin-r4  flex f-s-0">
              《{{ i18n['用户协议'] }}》
            </text>
            <text @click="go('/pagesB/user/rules?type=2')" class="t-color-blue1  flex f-s-0">《{{
                i18n['隐私政策']
              }}》
            </text>
          </view>
          <view class="padding-6"></view>
          <xieyi ref='xieyi' @agree="agree"></xieyi>
        </view>

        <view @click="login"
              class="flex f-a-c f-j-c b-radius-30 h-44 bg-color-linear-y t-color-w f-w-500 margin-t20">
          {{ i18n['登录'] }}
        </view>

        <view @click="go('/pages/index/home')"
              class="flex f-a-c f-j-c b-radius-30 h-44 bg-color-f7 t-color-black f-w-500 margin-t20">游客模式
        </view>

        <view class="flex f-j-s ">
          <view @click="toRegister" class="f12-size  padding-tb20">{{ i18n['注册'] }}</view>
          <view class="f12-size  padding-tb20"></view>
          <view @click="go('/pagesB/passport/password')" class="flex f-a-c">
            <text class="f12-size ">{{ i18n['忘记了'] }}</text>
            <text class="f12-size t-color-y">{{ i18n['找回密码'] }}</text>
          </view>
        </view>

      </view>
    </view>

    <!--    <block v-if="isXcx">-->
    <!--      <view class="padding-lr12">-->
    <!--        <view class="padding-20"></view>-->
    <!--        <view style="padding-top: 20vh;"></view>-->
    <!--        <view class="f30-size f-w-b flex f-a-c f-j-c">{{i18n['登录之后更精彩']}}</view>-->
    <!--      </view>-->
    <!--      <view class="flex f-a-c f-j-c f-c">-->
    <!--        <button  style="width: 68%;border-radius: 100px;" class="flex f-a-c f-j-c  bg-color-f7 h-60  padding-lr15" @click="getUserInfo">-->
    <!--          <image class="w-30 margin-r4" src="../../static/images/wx_icon.png" mode="widthFix"></image>-->
    <!--          <text class="f18-size">{{i18n['微信快捷登录']}}</text>-->
    <!--        </button>-->
    <!--        <view @click="go('/pages/index/index')" style="width: 68%;border-radius: 100px;" class="flex f-a-c f-j-c  bg-color-f7 h-60  padding-lr15 margin-t20">{{i18n['暂不登录']}}</view>-->

    <!--        <updateHeadNickname ref="updateHeadNickname" :openId="openId" @getUser="getUser" :currentPage="currentPage"></updateHeadNickname>-->
    <!--      </view>-->
    <!--      <view></view>-->
    <!--    </block>-->
    <block v-if="isXcx">
      <view>
        <view id="logoImg">
          <image mode="scaleToFill" style="width: 50%;height: 50%" :src="logo"
                 border-radius="30px"></image>
        </view>
        <view class="title" id="h1">{{ webName }}</view>
        <view class="title" id="h2">素材快速分享</view>
        <view class="title" id="h3">本平台提供用户方便快捷的多平台自媒体素材下载</view>
        <view style="padding: 10px">
          <u-button type="error" @click="getPhoneClick" v-if="!isAgree">
            授权手机号登录
          </u-button>
          <u-button type="error" @getphonenumber="toAuthAndLogin" v-if="isAgree" open-type="getPhoneNumber">
            授权手机号登录
          </u-button>
          <u-button :custom-style="customStyle" plain type="warning" @click="loginUseOtherPhone">输入手机号登录
          </u-button>
          <u-button :custom-style="customStyle" plain type="primary" @click="gotoHome">
            游客访问
          </u-button>
        </view>
        <view @click="isAgree = !isAgree" class="flex f-a-c margin-t12">
          <view class="padding-6"></view>
          <text :class="isAgree ? 'van-icon-checked t-color-y' : 'van-icon-circle t-color-b'"
                class="flex f-a-c f-j-c van-icon  f16-size margin-r4"></text>
          <text class="margin-r4 flex f-s-0">{{ i18n['已阅读并同意'] }}</text>
          <text @click="go('/pagesB/user/rules?type=1')" class="t-color-blue1 margin-r4  flex f-s-0">
            《{{ i18n['用户协议'] }}》
          </text>
          <text @click="go('/pagesB/user/rules?type=2')" class="t-color-blue1  flex f-s-0">《{{
              i18n['隐私政策']
            }}》
          </text>
        </view>
      </view>

      <u-modal v-model="showGetOtherPhone" title="验证手机号" show-cancel-button confirm-text="登录"
               @confirm="toLoginWithOtherPhone">
        <u-form :model="formGetOtherPhone" ref="uFormPhoneLogin" style="padding: 10px">
          <view class="flex h-50 b-radius-30 bg-color-f1 margin-t8">
            <view class="flex flex-1 padding-lr12">
              <u-form-item prop="phone">
                <u-input class="f16-size" v-model="formGetOtherPhone.phone" type="tel"
                         maxlength="11" :placeholder="i18n['请输入手机号码']"/>
              </u-form-item>
            </view>
          </view>

          <view class="flex h-50 b-radius-30 bg-color-f1 margin-t8">
            <view class="flex flex-1 padding-lr12">
              <u-form-item prop="sms">
                <u-input class="f16-size" v-model="formGetOtherPhone.sms" type="tel"
                         :placeholder="i18n['请输入验证码']"/>
              </u-form-item>
            </view>
            <view class="padding-6">
              <phone-code :phone="formGetOtherPhone.phone" :code="formGetOtherPhone.code"
                          :sendType="4" ref="phoneCodeRef"></phone-code>
            </view>
          </view>
        </u-form>


      </u-modal>
    </block>
  </view>
</template>
<script>
import xieyi from '../../pages/common/xieyi.vue';
import imgCode from '../../pages/common/imgcode.vue';
import updateHeadNickname from '../../pages/user/components/updateHeadNickname.vue';
import phoneCode from "@/pages/common/phonecode.vue";


const commonAPI = require('../../utils/api/common.js').default;
const WXBizDataCrypt = require('../../utils/WXBizDataCrypt.js');
const $ = require('../../utils/api.js');
const apiUrl = {
  phoneLogin: 'common/xcx/phoneLogin'
};
let nums = 0;
export default {
  data() {
    return {
      tabsList: [{
        name: "密码登录"
      }, {
        name: '验证码登录'
      }],
      tabsCurrent: 0,
      formPhoneCodeLogin: {
        phone: "",
        code: "102938111",
        sms: ""
      },
      formPhonePasswordLogin: {
        phone: "",
        code: "102938111",
        password: ""
      },
      customStyle: {
        "margin-top": "10px"
      },
      formGetOtherPhone: {
        phone: "",
        code: "102938111",
        sms: ""
      },
      rulesPhoneLogin: {
        phone: [
          {
            required: true,
            message: '手机号不能为空',
            // 可以单个或者同时写两个触发验证方式
            trigger: ['change', 'blur'],
          }
        ],
        sms: [
          {
            required: true,
            message: '验证码不能为空',
            trigger: ['change', 'blur'],
          }
        ]
      },
      showGetOtherPhone: false,
      srcLogo: "",
      currentPage: "login",
      openId: "",
      top: uni.getStorageSync('bartop') ? uni.getStorageSync('bartop') : 0,
      isIphonex: uni.getStorageSync('isIphonex') ? uni.getStorageSync('isIphonex') : false,
      isAgree: false,
      url: '',
      isXcx: false,
      inviteCode: "",
      session_key: "",
      phone: "",
      openid: "",
      webName: "",
      logo: ""
    };
  },
  onLoad: function (options) {
    this.getAppIdSecret()

    let data = uni.getStorageSync('config') ? uni.getStorageSync('config') : '';
    this.webName = data.web_name
    this.logo = data.logo
    if (this.tabsCurrent === 1) {
      this.$nextTick(() => {
        this.$refs.phoneCodeRefGzh.resetZero()
      })
    }

    this.formPhoneCodeLogin.phone = ""
    this.formPhoneCodeLogin.sms = ""
    this.formPhonePasswordLogin.phone = ""
    this.formPhonePasswordLogin.password = ""
    this.url = options.url ? options.url : '';
    if (this.inviteCode == '') {
      this.inviteCode = getApp().globalData.tuijianren;
    }
    this.init();
    // #ifdef MP-WEIXIN
    // this.getToken();
    this.isXcx = true;
    // #endif
  },
  onShow() {
    // this.getAppIdSecret()
  },
  methods: {
    gotoHome() {
      this.go('/pages/index/home', 3, 2000);
    },
    //请求获取appid和secret
    getAppIdSecret() {
      let self = this
      let postData = {}
      //授权成功后拿openid和电话去登录
      $.ajax({
        url: commonAPI.getWxConfig,
        data: postData,
        method: 'GET',
        complete(res) {
          if (res.code === 200) {
            let appId = res.data.xcxAppId
            let secret = res.data.xcxSecret
            self.goGetSessionKey(appId, secret)
          } else {
            uni.showToast({
              title: res.message,
              icon: 'none'
            });
          }
        }
      });
    },
    goGetSessionKey(appId, secret) {
      const self = this
      uni.login({
        provider: 'weixin',
        success: res => {
          console.log(res)
          self.js_code = res.code
          //这里只能从后台去请求微信，以为这个地址在正式环境，设置不了安全请求域名，（uni.request请求的地址需要设置为安全域名）
          let postData = {
            appid: appId, //你的小程序的APPID
            secret: secret, //你的小程序秘钥secret,
            js_code: this.js_code, //uni.login 登录成功后的code
            grant_type: 'authorization_code' //此处为固定值
          }
          //授权成功后拿openid和电话去登录
          $.ajax({
            url: commonAPI.jscode2session,
            data: postData,
            method: 'GET',
            complete(res) {
              console.log(res)
              if (res.code === 200) {
                self.openid = res.data.openid
                self.session_key = res.data.session_key
              } else {
                uni.showToast({
                  title: res.message,
                  icon: 'none'
                });
              }
            }
          });
        }
      });
    },
    toAuthAndLogin(res) {
      this.phone_encryptedData = res.detail.encryptedData //用于解密
      this.phone_iv = res.detail.iv // 用于解密

      console.log(res, "获取手机号需要的参数");
      console.log(this.session_key, "获取手机号需要的参数1");
      console.log(this.phone_iv, "获取手机号需要的参数2");
      let pc = new WXBizDataCrypt('wxc53213d65b626fb5', this.session_key);
      let data = pc.decryptData(this.phone_encryptedData, this.phone_iv);
      console.log(data);
      if (data.phoneNumber != '') {
        this.phone = data.phoneNumber
      }
      // //得到手机号后去登录
      this.phoneLogin(this.phone, this.openid, null)
    },

    tabsClick(item) {
      console.log('item', item);
    },
    tabsChange(index) {
      if (index === 1) {
        this.$nextTick(() => {
          this.$refs.phoneCodeRefGzh.resetZero()
        })
      }
      this.tabsCurrent = index;
      this.formPhoneCodeLogin.sms = ""
      this.formPhoneCodeLogin.phone = ""
      this.formPhonePasswordLogin.phone = ""
      this.formPhonePasswordLogin.password = ""
    },


    toRegister() {
      $.go('/pagesB/passport/register')
    },
    loginUseOtherPhone() {
      const self = this;
      if (!self.isAgree) {
        uni.showToast({
          title: self.i18n['请阅读并同意用户协议'],
          icon: "none"
        });
      } else {
        self.showGetOtherPhone = true;
        self.formGetOtherPhone.phone = ""
        self.formGetOtherPhone.sms = ""

        self.$nextTick(() => {
          self.$refs.phoneCodeRef.resetZero()
          self.$refs.uFormPhoneLogin.setRules(this.rulesPhoneLogin);
        })
      }


    },
    toLoginWithOtherPhone() {
      this.$refs.uFormPhoneLogin.validate(valid => {
        if (valid) {
          //先去验证短信验证码
          this.veritySmsCode()
        } else {
          console.log('验证失败');
        }
      });
      this.showGetOtherPhone = true
    },
    veritySmsCode() {
      let self = this
      let postData = {
        "phone": self.formGetOtherPhone.phone,
        "code": self.formGetOtherPhone.sms,
      }

      //授权成功后拿openid和电话去登录
      $.ajax({
        url: commonAPI.veritySmsCode,
        data: postData,
        method: 'POST',
        complete(res) {
          if (res.code === 200) {
            self.toAuth(self.formGetOtherPhone.phone)
          } else {
            uni.showToast({
              title: res.message,
              icon: 'none'
            });
          }
        }
      });
    },
    toAuth(phone) {
      const self = this;
      // 去wx auth认证
      $.getToken().then(res => {
        if (res.errMsg == 'request:ok') {
          switch (res.data.code) {
            case 200:
              let data = res.data.data;
              let openid = data.openid
              let unionid = data.unionid;
              let session_key = data.session_key;
              self.getPhoneNumber(phone, openid, unionid, session_key)
              return
            case 500:
              uni.showToast({
                title: res.data.message,
                icon: 'none'
              });
          }
        }
      });
    },
    getPhoneNumber(phone, openid, unionid) {
      const self = this;
      self.username = phone
      if (self.username && typeof self.username !== 'undefined') {
        self.phoneLogin(self.username, openid, unionid)
      }
    },
    phoneLogin(phone, openid, unionid) {
      let self = this
      let postData = {
        "phone": phone,
        "openId": openid,
        "inviteCode": "8912058",
        "unionid": unionid,
        "registrationId": '', //	极光注册ID
      }
      //授权成功后拿openid和电话去登录
      $.ajax({
        url: apiUrl.phoneLogin,
        data: postData,
        method: 'POST',
        loading: true,
        complete(res) {
          uni.hideLoading(); // 加载成功后隐藏加载提示
          if (res.data && res.data.token) {
            uni.setStorageSync('token', res.data.tokenHead + ' ' + res.data.token);
            uni.showToast({
              title: '登录成功',
              icon: 'none'
            });
            self.showGetOtherPhone = false
            //跳转到首页
            self.getUser();
            self.go('/pages/index/home', 3, 2000);
          } else {
            uni.showToast({
              title: res.message,
              icon: 'none'
            });


          }
        }
      });
    },
    getPhoneClick() {
      const self = this;
      if (!self.isAgree) {
        uni.showToast({
          title: self.i18n['请阅读并同意用户协议'],
          icon: "none"
        });
        return false;
      }
    },


    getToken(a, b, user) {
      const self = this;
      // 登录获取token
      $.getToken().then(res => {
        if (res.errMsg == 'request:ok') {
          switch (res.data.code) {
            case 200:
              let data = res.data.data;
              uni.setStorageSync('session_key', data.session_key);
              uni.setStorageSync('xcxopenid', data.openid);
              uni.setStorageSync('unionid', data.unionid);
              nums += 1;
              if (a) {
                if (nums >= 6) {
                  nums = 0;
                  uni.showToast({
                    title: '授权失败,请重新授权',
                    icon: 'none'
                  });
                } else {
                  self.postUserInfo(a, b, user, data.session_key);
                }
              }
              return
            case 500:
              uni.showToast({
                title: res.data.message,
                icon: 'none'
              });
          }
        }
      });
    },
    /**
     * 从微信服务器获取用户信息
     */
    getUserInfo: function (e) {
      uni.getUserProfile({
        desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
        success: res => {
          // 提交用户数据
          let encryptedData = res.encryptedData;
          let iv = res.iv;
          this.postUserInfo(encryptedData, iv, res.userInfo);

        }
      });
    },

    /**
     * 提交用户信息
     */
    postUserInfo: function (a, b, user, session_key) {
      const self = this;
      if (!session_key) {
        session_key = ''
      }
      // if (!uni.getStorageSync('unionid')) {//公众号和小程序一起才需要unionid
      // 	self.getToken(a, b, user);
      // 	return;
      // }
      if (!uni.getStorageSync('session_key') && session_key != '') {
        self.getToken(a, b, user);
        return;
      }
      let postData = {
        encryptedData: a,
        iv: b,
        sessionKey: session_key != '' ? session_key : uni.getStorageSync('session_key'),
        openId: uni.getStorageSync('xcxopenid'),
        unionId: uni.getStorageSync('unionid'),
      };
      $.ajax({
        url: 'common/xcx/regitser',
        data: postData,
        method: 'POST',
        complete(res) {
          self.socket.close();
          self.socket.creatSocket({
            onMessage(res) {
            }
          })
          if (res.data && res.data.token) {
            uni.setStorageSync('token', res.data.tokenHead + ' ' + res.data.token);
          } else {
            //'session_key'本地缓存过期
            // uni.removeStorageSync('session_key');
            // session_key 已经失效，需要重新执行登录流程
            self.getToken(a, b, user);

            return;
          }
          if (res.code == 200) {
            uni.showToast({
              title: '登录成功',
              icon: 'none'
            });
            //先根据是否第一次登录来显示
            if (res.data.isRegister === "1") {
              //如果是第一次注册
              self.$refs.updateHeadNickname.init()
              self.openId = res.data.openId
            } else {
              self.getUser();
            }


          }
        }
      });
    },
    agree() {
      this.isAgree = true;
    },
    login() {
      const self = this;
      if (!self.isAgree) {
        // $.$toast(self.i18n['请阅读并同意用户协议']);
        self.$refs.xieyi.open();
        return;
      }
      if (self.tabsCurrent === 0) {
        if (self.formPhonePasswordLogin.phone == '') {
          self.$toast(self.i18n['请输入登录账号']);
          return;
        }
        if (self.formPhonePasswordLogin.password == '' || self.formPhonePasswordLogin.password.length < 6) {
          self.$toast(self.i18n['请输入正确密码']);
          return;
        }
        this.phonePasswordLogin()
      } else if (self.tabsCurrent === 1) {
        if (self.formPhoneCodeLogin.phone == '') {
          self.$toast(self.i18n['请输入登录账号']);
          return;
        }
        if (this.formPhoneCodeLogin.sms == '') {
          self.$toast(self.i18n['请输入验证码']);
          return;
        }
        this.phoneCodeLogin()
      }


    },
    phonePasswordLogin() {
      const self = this
      $.ajax({
        url: 'common/login',
        data: {
          username: self.formPhonePasswordLogin.phone,
          password: self.formPhonePasswordLogin.password,
          type: 1,
          registrationId: '', //	极光注册ID
          captcha: self.formPhonePasswordLogin.code,
          gzhOpenId: uni.getStorageSync('gzhOpenId'),
          unionId: uni.getStorageSync('unionId'),
        },
        loading: true,
        success(res) {
          if (res.data && res.data.token) {
            uni.setStorageSync('token', res.data.tokenHead + ' ' + res.data.token);
            uni.setStorageSync('userInfo', res.data.member);
            $.$toast(self.i18n['登录成功']);
            if (self.url != '') {
              self.go(self.url, 2, 2000);
            } else {
              self.go('/pages/index/home', 3, 2000);
            }
            self.socket.close();
            self.socket.creatSocket({
              onMessage(res) {
              }
            })
          } else {
            uni.showToast({
              title: '登录失败',
              icon: 'none'
            });
          }


        }
      });
    },


    phoneCodeLogin() {
      const self = this
      let postData = {
        inviteCode: self.inviteCode,
        phone: self.formPhoneCodeLogin.phone,
        code: self.formPhoneCodeLogin.sms,
        registrationId: '', //	极光注册ID
        gzhOpenId: uni.getStorageSync('gzhOpenId'),
        unionId: uni.getStorageSync('unionId'),
        gzhNickname: uni.getStorageSync('gzhNickname'),
        gzhHeadimgurl: uni.getStorageSync('gzhHeadimgurl'),
      };
      $.ajax({
        url: 'common/gzh/phoneCodeLogin',
        data: postData,
        method: 'POST',
        complete(res) {
          if (res.data && res.data.token) {
            uni.setStorageSync('token', res.data.tokenHead + ' ' + res.data.token);
            uni.setStorageSync('userInfo', res.data.member);
            $.$toast(self.i18n['登录成功']);
            if (self.url != '') {
              self.go(self.url, 2, 2000);
            } else {
              self.go('/pages/index/home', 3, 2000);
            }
            self.socket.close();
            self.socket.creatSocket({
              onMessage(res) {
              }
            })
          } else {
            uni.showToast({
              title: '登录失败',
              icon: 'none'
            });
          }
        }
      });
    },

    getUser: function () {
      const self = this;
      $.ajax({
        url: 'member/getUser',
        data: {},
        method: 'GET',
        success(res) {
          uni.setStorageSync('userInfo', res.data);
          if (!res.data.phone) {//无绑定手机情况下前往绑定手机
            $.go('/pagesB/wxAuth/bindphone', 2);
          } else {
            if (self.url != '') {
              self.go(self.url, 2, 2000);
            } else {
              self.go('/pages/index/home', 3, 2000);
            }
            self.socket.close();
            self.socket.creatSocket({
              onMessage(res) {
              }
            })

          }
        }
      });
    },
    init() {
    },


  },
  computed: {
    i18nUser() {
      return this.$t('user')
    },
    i18n() {
      return this.$t('login')
    },
    i18nXieyi() {
      return this.$t('xieyi')
    },
  },
  created() {
  },
  mounted() {
  },
  destroyed() {
  },
  components: {
    phoneCode,
    imgCode,
    xieyi,
    updateHeadNickname
  },
  onPullDownRefresh() {
  },
  onReachBottom() {
  }
}
</script>
<style scoped>
@import url('../../static/css/passport/login.css');
@import url('../../static/css/page/white.css');

.title {
  text-align: center;
}

#h1 {
  font-weight: bolder;
  font-size: xx-large;
  font-family: cursive;
}

#h2 {
  margin-top: 10px;
  font-weight: bold;
  font-size: large;
  font-family: cursive;
}

#h3 {
  margin-top: 20px;
  margin-bottom: 20px;
  font-size: small;
}

#logoImg {
  height: 100%;
  width: 100%;
  display: flex; /* 设置容器为flex布局 */
  justify-content: center; /* 在主轴上对齐内容到中心位置 */
  align-items: center; /* 在交叉轴上对齐内容到中心位置 */

}
</style>
